package cryptx

import (
	"codeup.aliyun.com/lsxd/zltx/adapter/utils/cryptx/rsa"
	"codeup.aliyun.com/lsxd/zltx/adapter/utils/cryptx/sm2"
)

// Crypto 加密/解密接口
type Crypto interface {
	Encrypt(data string) (string, error)
	Decrypt(data string) (string, error)
}

type CryptoBuilder interface {
	Build() Crypto
}

// ByDes DES加密
func ByDes() *desBuilder {
	return &desBuilder{
		base: NewBaseCrypto(),
	}
}

// By3Des 3DES加密
func By3Des() *tripledesBuilder {
	return &tripledesBuilder{base: NewBaseCrypto()}
}

// ByAes AES加密
func ByAes() *aesBuilder {
	return &aesBuilder{base: NewBaseCrypto()}
}

// BySm2 SM2加密
func BySm2() *sm2Builder {
	return &sm2Builder{base: &sm2.Options{}}
}

// BySm4 SM4加密
func BySm4() *sm4Builder {
	return &sm4Builder{base: NewBaseCrypto()}
}

// ByRsa RSA加密
func ByRsa() *rsaBuilder {
	return &rsaBuilder{base: &rsa.Options{}}
}

// Encrypt 加密
func Encrypt(b CryptoBuilder, data string) (string, error) {
	return b.Build().Encrypt(data)
}

// Decrypt 解密
func Decrypt(b CryptoBuilder, data string) (string, error) {
	return b.Build().Decrypt(data)
}
